const sendBtn = document.querySelector('.input_sub')
const input = document.querySelector('.input_txt')
const talkListInput = document.querySelector('.talk_list')
sendBtn.addEventListener('click', async function () {
  try {
    const spoken = input.value
    if (!spoken) return alert('内容不能为空')
    const li2 = document.createElement('li')
    li2.className = 'right_word'
    li2.innerHTML = `<img src="img/person02.png" />
      <span> ${spoken} </span>`
    talkListInput.appendChild(li2)
    resetui()
    input.value = ''
    const { data: res } = await axios.get(
      ' http://ajax-api.itheima.net/api/robot',
      {
        params: { spoken },
      }
    )
    const robot = res.data.info.text
    console.log(robot)
    const li3 = document.createElement('li')
    li3.className = 'left_word'
    li3.innerHTML = `<img src="img/person01.png" />
      <span> ${robot} </span>`
    talkListInput.appendChild(li3)
    resetui()
  } catch (error) {
    console.log(error)
  }
})

input.addEventListener('keyup', function (e) {
  if (e.key === 'Enter') sendBtn.click()
})
